//
//  YBStoryitemCollectionViewCell.m
//  OurTourism
//
//  Created by 孟镇 on 15/11/25.
//  Copyright © 2015年 Devil_Coming. All rights reserved.
//

#import "YBStoryitemCollectionViewCell.h"

@interface YBStoryitemCollectionViewCell ()
@property (nonatomic, strong)UIImageView *coverImg;
@property (nonatomic, strong)UILabel *titleLable;
@property (nonatomic, strong)UIImageView *photoImg;
@property (nonatomic, strong)UILabel *nameLable;
@property (nonatomic, strong)UILabel *location;
@property (nonatomic, strong)UIImageView *img; //阴影

@end

@implementation YBStoryitemCollectionViewCell
#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.coverImg = [[UIImageView alloc]init];
        [self.contentView addSubview:self.coverImg];
        self.coverImg.contentMode = UIViewContentModeScaleAspectFill;
        self.coverImg.clipsToBounds = YES;

        self.img = [[UIImageView alloc]init];
        [self.contentView addSubview:self.img];
        self.img.image = [UIImage imageNamed:@"jiabian2"];
        self.img.frame = CGRectMake(0, 0, (self.frame.size.width - 30) / 2, 150);
        [self.contentView addSubview:self.img];
        
        self.location = [[UILabel alloc]init];
        [self.coverImg addSubview:self.location];
        self.location.font = [UIFont fontWithName:@"Arial" size:11];
        self.location.textColor = [UIColor whiteColor];

        self.titleLable = [[UILabel alloc]init];
        self.titleLable.numberOfLines = 2;
        [self.contentView addSubview:self.titleLable];
        self.titleLable.textColor = [UIColor darkGrayColor];
        
        self.titleLable.font = [UIFont systemFontOfSize:12];
        self.photoImg = [[UIImageView alloc]init];
        self.photoImg.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
        [self.contentView addSubview:self.photoImg];
        self.nameLable = [[UILabel alloc]init];
        self.nameLable.font = [UIFont systemFontOfSize:10];
        
        self.nameLable.textColor = [UIColor darkGrayColor];
        [self.contentView addSubview:self.nameLable];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    [self.coverImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(0);
        make.left.mas_equalTo(self.contentView).offset(0);
        make.size.mas_equalTo(CGSizeMake(layoutAttributes.size.width, 150));
    }];
    [self.location mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.coverImg).offset(-15);
        make.left.mas_equalTo(self.contentView).offset(10);
        make.size.mas_equalTo(CGSizeMake(layoutAttributes.size.width - 20, 15));
    }];
    [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.coverImg).offset(45);
        make.left.mas_equalTo(self.contentView).offset(10);
        make.size.mas_equalTo(CGSizeMake(layoutAttributes.size.width - 20, 30));
    }];
    [self.photoImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.coverImg).offset(85);
        make.left.mas_equalTo(self.contentView).offset(10);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
        self.photoImg.layer.masksToBounds = YES;
        self.photoImg.layer.cornerRadius = 15;
   [self.nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
       make.bottom.mas_equalTo(self.coverImg).offset(80);
       make.left.mas_equalTo(self.contentView).offset(60);
       make.size.mas_equalTo(CGSizeMake(100, 15));
   }];
}
#pragma mark - 首页故事赋值
- (void)setRecommendModel:(YBDestinationModel *)recommendModel
{
    [self.coverImg sd_setImageWithURL:[NSURL URLWithString:recommendModel.index_cover] ];
    self.titleLable.text = recommendModel.index_title;
    self.location.text = recommendModel.poiName;
}

- (void)setUserModel:(YBDestinationModel *)userModel
{
    [self.photoImg sd_setImageWithURL:[NSURL URLWithString:userModel.avatar_m] placeholderImage:nil];
    self.nameLable.text = userModel.name;
}

#pragma mark - 全部页赋值
- (void)setStoryAllModel:(YBDestinationModel *)storyAllModel
{
    [self.coverImg sd_setImageWithURL:[NSURL URLWithString:storyAllModel.index_cover] ];
    self.titleLable.text = storyAllModel.index_title;
    self.location.text = storyAllModel.poiName;
}
- (void)setStoryUserModel:(YBDestinationModel *)storyUserModel
{
    [self.photoImg sd_setImageWithURL:[NSURL URLWithString:storyUserModel.index_cover] placeholderImage:nil];
    self.nameLable.text = storyUserModel.name;
}


@end
